#!/bin/bash

export BUILD_ID=dontkillme
#抹掉本地记录
git checkout src/main/webapp/index.jsp
git checkout src/main/resources/tangyuan-configuration.xml
#替换版本号
sed -i "s/__ver/$BUILD_NUMBER/g" src/main/webapp/index.jsp
# 替换数据库参数
sed -i 's/root/jxadmin/g' src/main/resources/tangyuan-configuration.xml 
sed -i 's/123456/123456/g' src/main/resources/tangyuan-configuration.xml 
sed -i 's/127.0.0.1/10.10.10.81/g' src/main/resources/tangyuan-configuration.xml 
sed -i 's/jxcms/jxsy/g' src/main/resources/tangyuan-configuration.xml 

#打包
mvn package -Dmaven.test.skip=true
#杀死老的tomcat
kill -9 $(ps aux | grep java | grep data | grep -v grep | awk '{print $2}')
#等着java进程结束
while true; do
  used=$(netstat -anp | grep LISTEN | grep 81 -w)
  if [ -n "$used" ] ; then
    sleep 5
  else
    break
  fi
done
# 删除旧的war包和项目目录;拷贝新的war包到项目目录
rm /data/tomcat8/webapps/ROOT* -rf
cp target/qdcloud.war /data/tomcat8/webapps/ROOT.war
# 启动tomcat进程
/data/tomcat8/bin/startup.sh
